package com.chongxinlaiguo.mapstruct.dto.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 支付方式枚举
 */
@AllArgsConstructor
@Getter
public enum PayMethodEnum {
    // 国内支付
    POS(0,"scancode", "扫码支付",true),
    WX(1,"wxapplet", "微信支付",true),
    ALI(2,"aliapplet", "支付宝支付",true),
    YUN_CLOUD_PAY(3,"yuncloudapplet", "云闪付小程序支付",true),

    // 国外支付支持的银行卡支付
    CREDIT_DEBIT_CARD(4,"credit/debit card", "银行卡支付",false),
    // 马来RazorPay支付公司
    GRAB_PAY(5,"grabpay", "grabpay",false),
    TOUCHNGO(6,"touchngo", "touchngo",false),
    FPX(7,"fpx", "fpx",false),
    WALLET_PAY(8,"wallet","钱包支付",false),

    // 美国Square支付公司
    APPLE_PAY(9,"applepay", "applepay",false),
    GOOGLE_PAY(10,"googlepay", "googlepay",false),

    // 数据迁移时用的
    BONUSLINK(11,"bonuslink", "bonuslink",false),
    BOOST(12,"boost", "boost",false),
    CIMBCLICK(13,"cimbclick", "cimbclick",false),
    ELITECLUB(14,"eliteclub", "eliteclub",false),
    MAYBANKQR(15,"maybankqr", "maybankqr",false),
    OFFICERCHECK(16,"officercheck", "officercheck",false),
    ONLINE_TRANSFER(17,"onlinetransfer", "onlinetransfer",false),
    SARAWAK_PAY(18,"sarawakpay", "sarawakpay",false),
    SETEL(19,"setel", "setel",false),
    SHOPEE_PAY(20,"shopeepay", "shopeepay",false),
    SUNWAY_PALS(21,"sunwaypals", "sunwaypals",false),
    GOBIZ(22,"gobiz", "gobiz",false),
    ALIPAY_PLUS(23,"alipayplus", "alipayplus",false),
    MAYBANK(24,"maybank", "maybank",false),
    PAYDEE(25,"paydee", "paydee",false),

    // 泰国蚂蚁支付 APP、H5、C扫B使用
    TRUEMONEY(26,"truemoney", "truemoney",false),
    RABBIT_LINE_PAY(27,"rabbit_line_pay", "rabbit_line_pay",false),
    WALLET_WECHAT_PAY(28,"wallet_wechat_pay", "wallet_wechat_pay",false),
    BANKAPP_BANGKOKBANK(30,"bankapp_bangkokbank", "bankapp_bangkokbank",false),
    BANKAPP_BANKOFAYUDHYA(31,"bankapp_bankofayudhya", "bankapp_bankofayudhya",false),
    BANKAPP_SIAMCOMMERCIALBANK(32,"bankapp_siamcommercialbank", "bankapp_siamcommercialbank",false),
    BANKAPP_KASIKORNBANK(33,"bankapp_kasikornbank", "bankapp_kasikornbank",false),
    BANKAPP_KRUNGTHAIBANK(34,"bankapp_krungthaibank", "bankapp_krungthaibank",false),

    // 泰国蚂蚁支付 POS C扫B使用
    // 同一个type的原因是支付公司对于pos使用和app/h5使用，所需要的参数一样
    PROMPTPAY(29,"promptpay", "promptpay",false),
    // 和type=26区分开的原因是支付公司需要的参数不一样
    POS_TRUEMONEY(35,"pos_truemoney", "truemoney pos展示",false),
    // 和type=28区分开的原因是支付公司需要的参数不一样
    POS_WALLET_WECHAT_PAY(36,"pos_wechatpay", "wallet_wechat_pay pos展示",false),

    // 印尼支付
    QRIS(37, "qris", "qris扫码支付", false),
    OVO(38, "ovo", "ovo钱包支付", false),

    // 新加坡数据迁移
    ENETS_DBS(39,"eNETS-DBS", "eNETS-DBS",false),
    ENETS_OCBS(40,"eNETS-OCBS", "eNETS-OCBS",false),
    ENETS_SCB(41,"eNETS-SCB", "eNETS-SCB",false),
    ENETS_UOS(42,"eNETS-UOS", "eNETS-UOS",false),
    ALIPAY(43,"alipay", "alipay",false),
    PAYNOW(44,"paynow", "paynow",false),

    // 越南支付
    DOMESTIC_CARDS(45, "domesticcards", "Domestic cards越南本地银行卡", false),
    VIETQR(46, "vietqr", "vietqr转账", false),
    MOMO(47, "momo", "momo钱包支付", false),
    ZALOPAY(48, "zalopay", "zalopay钱包支付", false),
    RAZER_EDC(49, "RAZER-EDC", "RAZER-EDC", false),
    RAZER_CARD(50, "RAZER-CARD", "RAZER-CARD", false),
    RAZER_ALIPAY_QR(51, "RAZER-ALIPAY-QR", "RAZER-ALIPAY-QR", false),



    CASH_PAY(98,"cashpay", "现金支付",false),
    OTHER(99,"other", "其他支付",false),


    ;

    private int type;
    private String code;
    private String desc;
    private boolean needCheckMchntPayMethod; // 是否需要校验MchntPayMethodEnum类

    public static Integer getPayType(String code){
        return Arrays.stream(PayMethodEnum.values()).filter(n->code.contains("SCAN")).map(PayMethodEnum::getType).findFirst().orElse(1);
    }

    public static List<Integer> getPayTypeList(String code){
        if ("SCANNED".equalsIgnoreCase(code)){
            return Collections.singletonList(POS.type);
        }else if ("MINI".equalsIgnoreCase(code)) {
            return Arrays.asList(WX.type,ALI.type);
        }
        return Collections.emptyList();
    }

    public static PayMethodEnum getPayType(Integer type){
        return Arrays.stream(PayMethodEnum.values()).filter(item -> item.type == type).findFirst().
                orElseThrow(() -> new RuntimeException("传入的数据不正确：" + type));
    }

    public static PayMethodEnum getByValue(Integer value){
        if(null == value){
            return null;
        }
        for (PayMethodEnum type:values()){
            if(type.getType() == value){
                return type;
            }
        }
        return null;
    }

    public static boolean checkValue(Integer value){
        return getByValue(value) != null;

    }

}
